package com.mike.swt.table;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import com.mike.swt.table.model.GameWorld;
import com.mike.swt.table.model.Person;
import com.mike.swt.table.model.Team;

public class MyTreeContentProvider implements ITreeContentProvider {

	@Override
	public Object[] getChildren(Object obj) {
		System.out.println("getChildren...");
		Object[] result = null;
		if(obj instanceof String) {
			result = GameWorld.getInstance().getAllTeam().toArray();
		} else if (obj instanceof Team) {
			result = ((Team) obj).getAllMember();
		} else if (obj instanceof Person) {
			result = null;
		} else {
			return null;
		}
		return result;
	}

	@Override
	public Object getParent(Object obj) {
//		System.out.println("getParent...");
//		Object result = null;
//		if(obj instanceof GameWorld) {
//		} else if (obj instanceof Team) {
//			result = GameWorld.getInstance();
//		} else if (obj instanceof Person) {
//			result = ((Person) obj).getTeam();
//		}
//		return result;
		return null;
	}

	@Override
	public boolean hasChildren(Object obj) {
		System.out.println("hasChildren...");
		if(obj instanceof Person) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public Object[] getElements(Object obj) {
		System.out.println("getElements...");
		Object[] result = null;
		if(obj instanceof String) {
			result = GameWorld.getInstance().getAllTeam().toArray();
		} else if (obj instanceof Team) {
			result = ((Team) obj).getAllMember();
		} else if (obj instanceof Person) {
		} else {
			result = new Object[1];
			result[0] = "GameWorld";
		}
		return result;
	}

	@Override
	public void dispose() {
		System.out.println("dispose");
	}

	@Override
	public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
		System.out.println("inputChanged...");
	}


}
